package com.shengqin.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.shengqin.pojo.grade.GradeModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 * 学校
 * </p>
 *
 * @author Rui.Zhou
 * @since 2023-12-05
 */
@TableName("t_school")
@Schema(name = "School对象", description = "学校")
@Data
public class School implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @Schema(description = "学校编码")
    private String code;

    @Schema(description = "学校名称")
    private String name;

    @Schema(description = "学校图标")
    private String icon;

    @Schema(description = "学校类型 1.小学;2.初中;3.高中;4.大学")
    private String schoolType;

    @Schema(description = "所在省")
    private String province;

    @Schema(description = "所在城市")
    private String city;

    @Schema(description = "所在区")
    private String area;

    @Schema(description = "详细地址")
    private String address;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "创建人")
    private Integer createUserId;

    @TableField(exist = false)
    private List<String> citys;
    @TableField(exist = false)
    private List<String> schoolTypes;
    @TableField(exist = false)
    private String schoolTypeText;
    @TableField(exist = false)
    private List<GradeModel> gradeList;
    @TableField(exist = false)
    private Integer classesNum;
    @TableField(exist = false)
    private Set<String> schoolIds;
    @TableField(exist = false)
    private String password;

    public List<String> getCitys() {
        List<String> cityList = new ArrayList<>();
        if(StringUtils.hasLength(this.province)){
            cityList.add(this.province);
        }
        if(StringUtils.hasLength(this.city)){
            cityList.add(this.city);
        }
        if(StringUtils.hasLength(this.area)){
            cityList.add(this.area);
        }
        return cityList;
    }

    public List<String> getSchoolTypes() {
        if(StringUtils.hasLength(schoolType)){
            return Arrays.asList(schoolType.split(","));
        }
        return new ArrayList<>();
    }

    public void setSchoolTypes(List<String> schoolTypes) {
        this.schoolTypes = schoolTypes;
    }

    public String getSchoolTypeText() {
        if(StringUtils.hasLength(this.schoolType)){
            List<String> schoolTypeTextList = new ArrayList<>();
            if (this.schoolType.contains("1")) {
                schoolTypeTextList.add("小学");
            }
            if (this.schoolType.contains("2")) {
                schoolTypeTextList.add("初中");
            }
            if (this.schoolType.contains("3")) {
                schoolTypeTextList.add("高中");
            }
            if (this.schoolType.contains("4")) {
                schoolTypeTextList.add("大学");
            }
            return String.join(",", schoolTypeTextList);
        }
        return "";
    }
}
